#ifndef __PID_H
#define __PID_H

#include "main.h"
#include "string.h"

#define  TPID 0

#if TPID
typedef struct {
    float target_val; //目标值
    float actual_val; //实际值
    float err; //当前偏差
    float err_last; //上次偏差
    float err_sum; //误差累计值
    float Kp, Ki, Kd; //比例，积分，微分系数

} tPid;
#else
typedef struct {
    float target_val;       //设定值
    float Kp;     //比例系数
    float Ki;      //积分系数
    float Kd;    //微分系数
    float lasterror;     //前一拍偏差
    float preerror;     //前两拍偏差
    float deadband;     //死区
    float actual_val; //输出值
} tPid;
#endif

extern tPid pidA, pidB;
extern tPid pidHW_Tracking; //红外循迹的PID

void PID_init();

float P_realize(tPid *pid, float actual_val);

float PI_realize(tPid *pid, float actual_val);

float PID_realize(tPid *pid, float actual_val);

#endif
